package com.neutch.test;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Xm {
    //使用DAO封装

    //"com.mysql.cj.jdbc.Driver"
    private static String driver="com.mysql.cj.jdbc.Driver";
    private static String url="jdbc:mysql://localhost:3306/test";
    private static String user="root";
    private static String password="123456";
    private static Connection conn;
    private static PreparedStatement statement;
    private static ResultSet res;
    static{
        //加载驱动
        try {
            Class.forName(driver);
            //连接驱动
            conn=DriverManager.getConnection(url,user,password);
            //执行SQL对象

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws SQLException {
        conn.setAutoCommit(false);
        try {
            String sql_0 = "insert into uservalue ('李四','999999','lisi@126.com','1988-10-23',700)";
            String sql_1 = "update user set money=money-500 where name='张三' ";
            String sql_2 = "update user set money=money-500 where name='李四' ";
            statement = conn.prepareStatement(sql_0);
            statement = conn.prepareStatement(sql_1);
            statement = conn.prepareStatement(sql_2);
            conn.commit();
        } catch (SQLException e){
            e.printStackTrace();
            conn.rollback();
        }

    }

}
